/**
* 对象值转码
* @params 传入需要的对象
* */
export function enCodeString (params) {
  for (let key in params) {
    params[key] = encodeURIComponent(params[key])
  }
  return params
}

/**
* 验证空值
* @data 需要验证的值
* 0是空
* 1不为空
* */
export function checkNull (data) {
  if (data === '' || data === null || data === undefined) return 0
  else return 1
}


/*
* 数字三维加逗号
* */
export function numberFormat (num) {
  return num === 'string' ? num : num.toString().replace(/\d(?=(?:\d{3})+\b)/g,'$&,')
}

/*
* 数组求和
* */
export function arrayTotal (arr) {
  let result = 0
  arr.forEach((val) => {
    result += val
  })
  return result
}

/*
* countUp
* */
export function setCountUp (id, endVal) {
  const options = {
    useEasing: true,
    useGrouping: true,
    separator: ',',
    decimal: '.',
  }
  const counter = new CountUp(id, 0, endVal, 0, 4, options)
  if (!counter.error) counter.start()
  else throw counter.error
}

